package com.ganee.agora.view

import android.content.Intent
import android.os.Bundle
import android.text.TextUtils
import androidx.lifecycle.ViewModelProviders
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.ganee.agora.R
import com.ganee.agora.viewmodel.WelcomeViewModel
import com.ganee.baselib.arouter.Constance
import com.ganee.baselib.httprequest.cache.ACache
import com.ganee.baselib.httprequest.cache.EnumKey
import com.ganee.baselib.httprequest.utils.PackageUtils
import com.ganee.baselib.mvvmlibrary.base.BaseActivity
@Route(path = Constance.ACTIVITY_URL_WELCOME)
class WelcomeActivity : BaseActivity<WelcomeViewModel>() {
    override fun getViewModel(): WelcomeViewModel {
        return ViewModelProviders.of(this@WelcomeActivity).get(WelcomeViewModel::class.java)
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_welcome)
        ARouter.getInstance().inject(this)
        jump()
    }

    private fun jump() {
        val thread = MyThread()
        thread.start()
    }

    inner class MyThread : Thread() {
        override fun run() {
            super.run()
            try {
                Thread.sleep(1000)
            } catch (e: InterruptedException) {
                e.printStackTrace()
            }
            val token = ACache.get(this@WelcomeActivity).getAsString(EnumKey.User.USER_TOKEN)
            if (TextUtils.isEmpty(token)) {
                ARouter.getInstance().build(Constance.ACTIVITY_URL_LOGIN).navigation()
                finish()
            } else {
                val intent = Intent()
                intent.setClass(this@WelcomeActivity,MainActivity::class.java)
                startActivity(intent)
//                ARouter.getInstance().build(Constance.ACTIVITY_URL_MAIN).navigation()
                finish()
            }
        }

    }
}
